﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class View_Admin_QuanLyLoaiTT : System.Web.UI.Page
{
    QLTinTuc tt = new QLTinTuc();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            GridView1.DataSource = tt.Load_LoaiTinTuc();
            GridView1.DataBind();
        }
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        tt.Insert_LoaiTinTuc(txtTen.Text);
        lblThongBao.Text = "Thêm thành công!!!";
        txtTen.Text = "";
        GridView1.DataSource = tt.Load_LoaiTinTuc();
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataSource = tt.Load_LoaiTinTuc();
        GridView1.DataBind();
        GridView1.Rows[e.NewEditIndex].Cells[0].Enabled = false;

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridView1.DataSource = tt.Load_LoaiTinTuc();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox maloai = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
        TextBox tenloai = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
        tt.Update_LoaiTT(maloai.Text, tenloai.Text);
        GridView1.EditIndex = -1;
        GridView1.DataSource = tt.Load_LoaiTinTuc();
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string maloai = (string)GridView1.Rows[e.RowIndex].Cells[0].Text.ToString();
        tt.Delete_LoaiTT(maloai);
        GridView1.DataSource = tt.Load_LoaiTinTuc();
        GridView1.DataBind();
    }
}
